<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<c:url var="ico_edit" value="images/icons/edit.gif" />
<c:url var="ico_delete" value="images/icons/cross.png" />
<c:url var="ico_security" value="images/icons/security_icon.png" />
<c:url var="ico_actions" value="images/icons/actions_icon.png" />
<c:url var="ico_redactor" value="images/icons/redactor_icon.png" />
<c:url var="ico_admin" value="images/icons/admin_icon.png" />
<c:url var="ico_close" value="images/icons/close_icon.png" />
<c:url var="ico_administration"
	value="images/icons/administration_icon.png" />
<c:url var="img_ctx_menu" value="images/context_menu.png" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Administration - <fmt:message key="appTitle" /></title>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/styles/base.css" />' />
<link rel="stylesheet" type="text/css"
	href='<c:url value="/styles/charte.css" />' />
	

<script type="text/javascript">
	

function getPosition(element)
{
	var left = 0;
	var top = 0;
	/*On récupère l'élément*/
	var e = document.getElementById(element);
	/*Tant que l'on a un élément parent*/
	while (e.offsetParent != undefined && e.offsetParent != null)
	{
		/*On ajoute la position de l'élément parent*/
		left += e.offsetLeft + (e.clientLeft != null ? e.clientLeft : 0);
		top += e.offsetTop + (e.clientTop != null ? e.clientTop : 0);
		e = e.offsetParent;
	}
	return new Array(left,top);
}

function hideMenu(){
	var menu = document.getElementById("context_menu");
	 menu.style.display="none";
}	
function showMenu(id,account_name,redactor, administrator,appPath)
{
	var idElem = "img-ctx-menu_"+id;
	var elem = document.getElementById(idElem);
	var position = getPosition(idElem);
	var x = position[0]+elem.width+15;
	var y = position[1];
	var menu = document.getElementById("context_menu");
	menu.style.display="";
	menu.style.position="fixed";
	menu.style.left=x+"px";
	menu.style.top= y+"px";
	menu.style.border="2px solid #1D6880";
	
	var anchor = document.getElementById("redactor");
	if (redactor){
		anchor.innerHTML="Retirer les droits de rédaction";
		anchor.setAttribute("href","/"+appPath+"/revokeredactor.htm?account_id="+id);
	}
	else{
		anchor.innerHTML="Attribuer les droits de rédaction";
		anchor.setAttribute("href","/"+appPath+"/grantredactor.htm?account_id="+id);
	}
	
	anchor = document.getElementById("administrator");
	if (administrator){
		anchor.innerHTML="Retirer les droits d'administration";
		anchor.setAttribute("href","/"+appPath+"/revokeadministrator.htm?account_id="+id);
	}
	else{
		anchor.innerHTML="Attribuer les droits d'administration";
		anchor.setAttribute("href","/"+appPath+"/grantadministrator.htm?account_id="+id);
	}
	var actionTitle=document.getElementById("actionsTitle");
	actionTitle.innerHTML="Actions - "+account_name;
}
	
</script>

</head>
<body>
	<div id="global"><jsp:include page="header.jsp" />
		<jsp:include page="menu.jsp" />
		<c:if test="${empty loggedUser.administrator}">
			<c:redirect url="/home.htm" />
		</c:if>
		<div id="contenu">
			<h2>
				<img style="cursor: pointer;" src="${ico_administration }"
					width="64px" height="64px" />
				<fmt:message key="label.accounts-management" />
			</h2>
			<hr>
			<div id="tableau" style="z-index: 0; position: relative;">
				<div
					style="width:300px;height:200px;display: none; z-index: 10; position: fixed; background-image: url('${img_ctx_menu}');"
					id="context_menu" align="center">
					<table width="95%" >
						<tr>
							<td></td>
						</tr>
						<tr>
							<td align="right"><img src="${ico_close}" width="16px"
								height="16px" onmousedown="javascript:hideMenu()">
							</td>
						</tr>
						<tr>
							<th id="actionsTitle" style="background-color: #1D6880;">Actions</th>
						</tr>
						<tr>
							<td></td>
						</tr>
						<tr align="center">
							<td><img src="${ico_redactor}" width="16px" height="16px">
								<a id="redactor" class="ctxMenu_link"></a></td>
						</tr>
						<tr align="center">
							<td><hr />
							</td>
						</tr>
						<tr align="center">
							<td><img src="${ico_admin}" width="16px" height="16px">
								<a id="administrator" href="" class="ctxMenu_link"></a></td>
						</tr>

					</table>
				</div>
				<p>
					<u><fmt:message key="label.search-accounts" /> :</u>
				</p>
				<form:form method="post" commandName="searchAccountsForm">
					<table>
						<tr>
							<td>Nom :</td>
							<td><form:input path="lastname" />
							</td>
							<td><form:errors path="lastname" cssClass="errorMsg" />
							</td>
						</tr>
						<tr>
							<td>Email :</td>
							<td><form:input path="mail" />
							</td>
							<td><form:errors path="mail" cssClass="errorMsg" />
							</td>
						</tr>
						<tr>
							<td colspan="2">&nbsp;</td>
						</tr>
						<tr>
							<td>&nbsp;</td>
							<td><input type="submit" name="submit" value="Rechercher">
							</td>
						</tr>
					</table>
				</form:form>
				<hr>
				<table class="accountsTable">
					<tr>
						<td align="center"><display:table export="false" requestURI=""
								name="listAccounts" defaultsort="2" defaultorder="descending"
								pagesize="5" class="faf.entities.ACcount" id="row">
								<display:column headerClass="accountsTableTh" property="lastname"
									title="Nom" sortable="true" />
								<display:column headerClass="accountsTableTh" property="firstname" title="Prénom"
									sortable="true" />
								<display:column headerClass="accountsTableTh" property="mail" title="Email" sortable="true"
									class="th2" />
								<display:column headerClass="accountsTableTh" titleKey="label.profile" >
									<c:if test="${row.redactor}">
										<img width="16" height="16" alt="Rédacteur" border="0"
											src="${ico_redactor}" />

									</c:if>
									<c:if test="${not row.redactor}">&nbsp;</c:if>

									<c:if test="${row.administrator}">
										<img width="16" height="16" alt="Administrateur" border="0"
											src="${ico_admin}" />

									</c:if>
									<c:if test="${not row.administrator}">&nbsp;</c:if>
								</display:column>
								<display:column headerClass="accountsTableTh" titleKey="label.actions" class="th2">
									<c:if test="${loggedUser.administrator}">
										<a
											href="<c:url value="/updateAccount.htm?account_id=${row.id}"/>"><img
											width="16" height="16" alt="Editer" border="0"
											src="${ico_edit}" /></a>
										<img style="cursor: pointer;" alt="Supprimer" width="16"
											height="16" border="0" src="${ico_delete}"
											onclick="javascript:if(confirm('Voulez vous confirmer la suppression du compte de <c:out value="${row.firstname}"/>, <c:out value="${row.lastname}"/>  ?') ) {location='deleteAccount.htm?account_id=<c:out value="${row.id}"/>';return false;}" /><img src='${ico_actions}' id="img-ctx-menu_${row.id}"
											onclick="javascript:account_name = '${row.lastname }, ${row.firstname }';showMenu(${row.id},account_name, ${row.redactor}, ${row.administrator},'<c:out value="${appPath}"/>' )">

									</c:if>
								</display:column>
								<display:footer >
									<tr >
										<td colspan="5">&nbsp;</td>
									</tr>
								</display:footer>
							</display:table></td>
					</tr>
				</table>

			</div>
		</div>
		<jsp:include page="footer.jsp" /></div>
</body>
</html>